<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/6
 * Time: 13:32
 */

namespace Portal\Controller;

use Common\Controller\AdminbaseController;

class PartnersController extends AdminbaseController {
    function _initialize() {
        parent::_initialize();
    }
    public function index(){
        $re=M('partners')->select();
        $this->assign('result',$re);
        $this->display();
    }
    public function add(){
        $this->display();
    }
    public function add_post(){
        $data['img'] = sp_asset_relative_url(I('post.img'));
        $data['title'] = I('post.title');
        $data['type'] = I('post.type');
        $data['text'] = htmlspecialchars_decode(I('post.text'));
        $data['createtime'] = I('post.createtime');
        if(M('partners')->add($data)){
            $this->success('添加成功');
        }else{
            $this->error('添加失败');
        }
    }
    public function edit(){
        $id=I('get.id');
        $post=M('partners')->where("id = $id")->find();
        $this->assign('post',$post);
        $this->display();
    }
    public function edit_post(){
        $id=I('post.id');
        $data['img'] = sp_asset_relative_url(I('post.img'));
        $data['title'] = I('post.title');
        $data['type'] = I('post.type');
        $data['text'] = htmlspecialchars_decode(I('post.text'));
        $data['createtime'] = I('post.createtime');
        if(M('partners')->where("id = $id")->save($data)){
            $this->success('修改成功');
        }else{
            $this->error('修改失败');
        }
    }
    public function delete(){
        $id=I('get.id');
        if(isset($id)){
           if(M('partners')->where("id = $id")->delete()){
               $this->success("删除成功");
           }else{
               $this->error('删除失败');
           }
        }else{
            $this->error('删除失败');
        }
    }
}